package com.ruoyi.web.controller.purchase;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.purchase.domain.TPurchaseOrderItem;
import com.ruoyi.purchase.service.ITPurchaseOrderItemService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 采购明细Controller
 * 
 * @author ruoyi
 * @date 2025-09-24
 */
@RestController
@RequestMapping("/system/purchase/item")
public class TPurchaseOrderItemController extends BaseController
{
    @Autowired
    private ITPurchaseOrderItemService tPurchaseOrderItemService;

    /**
     * 查询采购明细列表
     */
    @PreAuthorize("@ss.hasPermi('system:item:list')")
    @GetMapping("/list")
    public TableDataInfo list(TPurchaseOrderItem tPurchaseOrderItem)
    {
        startPage();
        List<TPurchaseOrderItem> list = tPurchaseOrderItemService.selectTPurchaseOrderItemList(tPurchaseOrderItem);
        return getDataTable(list);
    }

    /**
     * 导出采购明细列表
     */
    @PreAuthorize("@ss.hasPermi('system:item:export')")
    @Log(title = "采购明细", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TPurchaseOrderItem tPurchaseOrderItem)
    {
        List<TPurchaseOrderItem> list = tPurchaseOrderItemService.selectTPurchaseOrderItemList(tPurchaseOrderItem);
        ExcelUtil<TPurchaseOrderItem> util = new ExcelUtil<TPurchaseOrderItem>(TPurchaseOrderItem.class);
        util.exportExcel(response, list, "采购明细数据");
    }

    /**
     * 获取采购明细详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:item:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tPurchaseOrderItemService.selectTPurchaseOrderItemById(id));
    }

    /**
     * 新增采购明细
     */
    @PreAuthorize("@ss.hasPermi('system:item:add')")
    @Log(title = "采购明细", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TPurchaseOrderItem tPurchaseOrderItem)
    {
        return toAjax(tPurchaseOrderItemService.insertTPurchaseOrderItem(tPurchaseOrderItem));
    }

    /**
     * 修改采购明细
     */
    @PreAuthorize("@ss.hasPermi('system:item:edit')")
    @Log(title = "采购明细", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TPurchaseOrderItem tPurchaseOrderItem)
    {
        return toAjax(tPurchaseOrderItemService.updateTPurchaseOrderItem(tPurchaseOrderItem));
    }

    /**
     * 删除采购明细
     */
    @PreAuthorize("@ss.hasPermi('system:item:remove')")
    @Log(title = "采购明细", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tPurchaseOrderItemService.deleteTPurchaseOrderItemByIds(ids));
    }
}
